package action;

import java.io.IOException;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.Meeting;
import biz.MeetingBiz;
import biz.impl.MeetingBizImpl;

public class AddAction extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession(false);
		if (session == null){
			response.sendRedirect("login.jsp");
		}
		request.setCharacterEncoding("utf-8");
		// 获取数据
		String topic = request.getParameter("topic");
		String content = request.getParameter("content");
		String meetingDate = request.getParameter("topic");
		String person = request.getParameter("person");
		String completeTime = request.getParameter("completeTime");
		String remark = request.getParameter("remark");
		String participants = request.getParameter("participants");
		String type = request.getParameter("type");
		String depName = request.getParameter("depName");
		// 封装数据
		Meeting meeting = new Meeting();
		meeting.setTopic(topic);
		meeting.setContent(content);
		meeting.setMeetingdate(new Date());
		meeting.setPerson(person);
		meeting.setCompletetime(new Date(completeTime));
		meeting.setRemark(remark);
		meeting.setParticipants(participants);
		meeting.setType(type);
		//meeting.setDepname(depName);
		//保存数据
		MeetingBiz mb = new MeetingBizImpl();
		boolean success = mb.save(meeting);
		if (success == true) {
			response.sendRedirect("SearchAction");
		} else {
			response.sendRedirect("add_meeting.jsp");
		}
	}

}
